package com.projectmanagement.model.data;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "Roles")
public class Role implements Serializable {

	private static final long serialVersionUID = 1824131409374374796L;

	@Id
	@Column(name = "id")
	@GeneratedValue
	private long id;

	@Column(name = "name", nullable = false)
	private String name = "";

	@Column(name = "description", nullable = false)
	private String description = "";

	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "ROLE_PERMISSIONS", 
			joinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }, 
			inverseJoinColumns = { @JoinColumn(name = "permission_id", referencedColumnName = "id") })
	private List<Permission> permissions;

	public Role() {
	}

	public Role(String name, String displayName) {
		this();
		this.name = name;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}

}
